<template>
  <div class="input-number">
    <button @click="handleIncrease(-1)">-</button>
    <g-input :value="currentValue" type="number" />
    <button @click="handleIncrease(1)">+</button>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      currentValue: this.value,
    }
  },
  watch: {
    value(val) {
      this.currentValue = val
    },
  },
  methods: {
    handleIncrease(val) {
      this.currentValue += val
      this.$emit('change', this.currentValue)
    },
  },
}
</script>

<style lang="scss" scoped>
.input-number {
  button,
  input {
    border: 1px solid #eee;
    line-height: 28px;
  }
  button {
    width: 30px;
  }
  input {
    border-left: 0;
    border-right: 0;
    text-align: center;
  }
}
</style>
